package 面试.停止线程;
//能停止的线程—异常法
class MyThread_03 extends Thread {
    public void run(){
        super.run();
        for(int i=0; i<500000; i++){
            if(this.interrupted()) {
                System.out.println("线程已经终止， for循环不再执行");
                break;
            }
            System.out.println("i="+(i+1));
        }
    }
}

public class Demo3 {
    public static void main(String args[]){
        Thread thread_03 = new MyThread_03();
        thread_03.start();
        try {
            Thread.sleep(2000);
            thread_03.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}